package ipgather.util;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;

import ipgather.constant.PortConstant;

public class HostUtil {
	
	public static boolean checkCollect(String host,int port){
		Socket socket = new Socket();
		boolean pass = true;
		try {
			socket.connect(new InetSocketAddress(host,port),PortConstant.COLLECT_TIME_OUT);
		} catch (UnknownHostException e) {
			pass = false;
		}catch (SocketTimeoutException to) {
			pass = false;
		} catch (IOException e) {
			pass = false;
		} finally {
			if(null!=socket&&!socket.isClosed()){
				try {
					socket.close();
				} catch (IOException e) {
					pass = false;
				}
			}
		}
		return pass;
	}
}
